﻿using SqlSugar;
using System.ComponentModel.DataAnnotations;
using Vampirewal.BlogCore.DataAccess;

namespace Vampirewal.BlogCore.TestWebApi;

public class MessageBoardPage : PageBase
{
    private SimpleClient<MessageBoardForm> _rep { get; set; }
    public MessageBoardPage(SimpleClient<MessageBoardForm> rep)
    {
        _rep = rep;
    }

    public override bool IsCache => false;
    public override string Title => "留言板";
    public override string MenuGroup => "说明";

    public override int MenuGroupSort => 0;
    public override int Sort => 3;

    public override List<Tag> Tags => new List<Tag>()
    {
        App.CreateTag("刷新之后显示最新留言", TagType.Primary),
    };

    public override List<PartContainer> PartContainers => new List<PartContainer>()
    {
        App.CreatePartContainer("留言", child =>
        {
            App.CreateForm<MessageBoardForm>().AddToChildren(child);
        }),

        App.CreatePartContainer("内容", async child =>
        {
            var list= await _rep.GetListAsync();

            App.CreateTable(list).AddToChildren(child);

            
        }),
    };


}

[SugarTable("MessageBoard", "留言板")]
[FormModel(true)]
[FormButton("提交", ButtonType.Success, ButtonExcuteType.Submit, "SubmitMessageBoard")]
[Table]
public class MessageBoardForm
{
    [SugarColumn(IsPrimaryKey = true, ColumnName = "Id", ColumnDescription = "主键", IsIdentity = false)]
    public string Id { get; set; }

    /// <summary>
    /// 提交人
    /// </summary>
    [SugarColumn(ColumnName = "Submitter", ColumnDescription = "提交人", IsNullable = true)]
    [TableItem("提交人")]
    [FormInput("提交人", "请输入提交人姓名")]
    [Required(ErrorMessage = "提交人不能为空")]
    public string Submitter { get; set; }

    /// <summary>
    /// 内容
    /// </summary>
    [SugarColumn(ColumnName = "Content", ColumnDescription = "内容", Length = 500, IsNullable = true)]
    [TableItem("内容")]
    [FormInput("内容", "请输入内容", 3)]
    public string Content { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [SugarColumn(ColumnName = "CreateTime", ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true)]
    [TableItem("时间")]
    public DateTime? CreateTime { get; set; }
}